package com.chaodev.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.dao.VolunteerWorkRecordDao;
import com.chaodev.base.dto.VolunteerWorkRecordDto;
import com.chaodev.base.model.VolunteerWorkRecord;
import com.chaodev.base.service.VolunteerWorkRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VolunteerWorkRecordServiceImpl implements VolunteerWorkRecordService {

    @Autowired
    private VolunteerWorkRecordDao volunteerWorkRecordDao;

    @Override
    public boolean addVolunteerWorkRecord(VolunteerWorkRecord volunteerWorkRecord) {
        return volunteerWorkRecordDao.insertVolunteerWorkRecord(volunteerWorkRecord) != 0;
    }

    @Override
    public boolean editVolunteerWorkRecord(VolunteerWorkRecord volunteerWorkRecord) {
        return volunteerWorkRecordDao.updateVolunteerWorkRecord(volunteerWorkRecord) != 0;
    }

    @Override
    public boolean removeVolunteerWorkRecord(VolunteerWorkRecord volunteerWorkRecord) {
        return volunteerWorkRecordDao.deleteVolunteerWorkRecord(volunteerWorkRecord.getId()) != 0;
    }

    @Override
    public List<VolunteerWorkRecord> getVolunteerWorkRecordList(VolunteerWorkRecordDto volunteerWorkRecordDto) {
        return volunteerWorkRecordDao.selectVolunteerWorkRecordList(volunteerWorkRecordDto);
    }

    @Override
    public PageInfo<VolunteerWorkRecord> getVolunteerWorkRecordPage(VolunteerWorkRecordDto volunteerWorkRecordDto) {
        PageHelper.startPage(volunteerWorkRecordDto.getPage(),volunteerWorkRecordDto.getRows());
        List<VolunteerWorkRecord> list = volunteerWorkRecordDao.selectVolunteerWorkRecordList(volunteerWorkRecordDto);
        PageInfo<VolunteerWorkRecord> pageInfo = new PageInfo<>(list, volunteerWorkRecordDto.getRows());
        return pageInfo;
    }
}
